using System;
using System.Collections.Generic;
using System.Text;

namespace Scheduler
{
    /*
     * An object of this class holds information about each scheduling slot
     * each scheduling slot is 30 minutes long initially.
     * The "int state" of each slot can be:
     * 0 -> Free (RMT maybe available but no appointments)
     * 1 -> Booked
     * 2 -> Preparation (booked for preparing the room for the next therapy)
     * Other information held by this class are:
     * the name of the therapy to be provided in that slot(String Therpay)
     * the name of the RMT available in that slot(String RMT)
     * the name of the customer who is attending the session(customer)
     */
    public class SchedSlot
    {
        private int id;
        private String therapy;
        private String rmt;
        private int state;
        private String customer;

        public SchedSlot()
        {
            id = -1;
            therapy = "";
            rmt = "";
            state = 0;
            customer = "";
        }

        public SchedSlot(Database db, int schedSlotID)
        {
            SchedSlot temp = db.readSchedSlot(schedSlotID);

            this.id = temp.id;
            this.therapy = temp.therapy;
            this.rmt = temp.rmt;
            this.state = temp.state;
            this.customer = temp.customer;
        }
        public SchedSlot(int id, int state, String rmtName, String therapyName, String customerName)
        {
            this.ID = id;
            this.State = state;
            therapy = String.Copy(therapyName);
            rmt = String.Copy(rmtName);
            customer = String.Copy(customerName);
        }
        public int ID
        {
            get { return id; }
            set { id = value; }
        }

        public String Therapy
        {
            get { return therapy; }
            set { therapy = String.Copy(value); }
        }

        public String RMT
        {
            get { return rmt; }
            set { rmt = String.Copy(value); }
        }

        public int State
        {
            get { return state; }
            set { state = value; }
        }


        public String Customer
        {
            get { return customer; }
            set { customer = String.Copy(value); }
        }


        /*
         * Returned String contains detailed information about the schedSlot 
         */
        public override String ToString()
        {
            if (this.state == 0)
            {
                return ((rmt == "") ? ("- - -") : ("RMT: " + rmt + " Status: Free"));
            }
            else
                return "RMT: " + rmt + ", Status: Booked, Customer: " + customer + ", Therapy: " +
                        therapy;
        }

        /* 
         * Returned String contains detailed information about the schedSlot
         */
        public String detailedSchedForRMTAdmin()
        {
            if (this.state == 0)
            {
                return ((rmt == "") ? ("- - -") : ("RMT: " + rmt + " Status: Free"));
            }
            else if (this.state == 1)
                return "RMT: " + rmt + ", Status: Booked, Customer: " + customer + ", Therapy: " +
                        therapy;

            else if (this.state == 2 && this.RMT != "")
            {
                return "RMT: " + rmt + ", Status: Preparation for Therapy: " + therapy;
            }

            else

                return "Status: Preparation for Therapy: " + therapy;


        }

        /* 
         * Returned String contains detailed information about the schedSlots occupied by
         * rmtName. It only contains partial information(RMTname & status) for other schedSlots.
         */
        public String detailedSchedForRMT(String rmtName)
        {
            if (this.state == 0)
            {
                return ((rmt == "") ? ("- - -") : ("RMT: " + rmt + " Status: Free"));
            }

            else if (this.state == 2 && this.RMT != "")
            {
                return "RMT: " + rmt + ", Status: Preparation for Therapy: " + therapy;
            }

            else if (this.state == 2 && this.RMT == "")
            {
                return "Status: Preparation for Therapy: " + therapy;
            }

            else if (this.state == 1 && this.rmt == rmtName)
            {
                return "RMT: " + rmt + ", Status: Booked, Customer: " + customer + ", Therapy: " +
                        therapy;
            }

            else
            {
                return ("RMT: " + rmt + " Status: Booked");
            }
        }


        /* 
         * Returned String contains detailed information about the schedSlots occupied by
         * custName. It only contains partial information(RMTname) for other schedSlots.
         */
        public String detailedSchedForCustomer(String custName)
        {
            if (this.state == 0)
            {
                return ((rmt == "") ? ("- - -") : ("RMT: " + rmt + " Status: Free"));//can change to show the status as well!(May help with the scheduling procedure)
            }

            else if (this.state == 1 && this.customer == custName)
            {
                return "RMT: " + rmt + ", Status: Booked, Customer: " + customer + ", Therapy: " +
                        therapy;
            }

            else
            {
                return ("RMT: " + rmt + " Status: Booked"); //can change to show the status as well!(May help with the scheduling procedure)
            }
        }

        public void writeToDatabse(Database db)
        {
            this.ID = db.writeSchedSlot(this);
        }
        /*
         * This method books a slot by setting the Customer name and the Therapy name
         * which values are taken as parameters to this method
         */
        internal void bookSchedSlot(Database db, String custName, String therName)
        {
            this.State = 1;
            this.Therapy = therName;
            this.Customer = custName;
            this.ID = db.writeSchedSlot(this);
        }

        /*
         * This method books a slot for preparation needed before a therapy session.
         * The name of the therapy that follows the preparation is set in this method and
         * it's value is taken as a parameter.
         * RMT may or may not be available. 
         */
        internal void bookSchedSlotForPrep(Database db, string therName)
        {
            this.State = 2;
            this.Therapy = therName;
            this.ID = db.writeSchedSlot(this);
        }

        /*
         * This method sets the slot free again. It removes the customer name and 
         * the therapy name which had been scheduled before.
         */
        internal void removeAppointment(Database db)
        {
            this.state = 0;
            this.Therapy = "";
            this.Customer = "";
            this.ID = db.writeSchedSlot(this);
        }

    }
}
